Skip to content

Refactor: extract OCR/QR result post-processing into TextRecognition#12

Merged
GamalAnwar merged 1 commit into
masterfrom
claude/solid-refactor-text-recognition
Jun 18, 2026
Merged

Refactor: extract OCR/QR result post-processing into TextRecognition#12
GamalAnwar merged 1 commit into
masterfrom
claude/solid-refactor-text-recognition

Conversation

@GamalAnwar

Copy link
Copy Markdown
Contributor

Summary

Target 1 of the remaining heavier slices (OCR/QR path). The pure post-processing of Vision results was buried inside the recognition closures and duplicated:

  • OCR line-join + empty-check + line-count appeared in both CaptureManager.runOCR and EditorView.performOCR.
  • QR payload → openable-URL decision lived inline in EditorView.performQRScan.

This lifts the testable logic out into a TextRecognition module that classifies already-extracted strings (so tests need no Vision objects):

TextRecognition.ocrOutcome(from: [String]) -> OCROutcome          // .noText | .copied(text, lineCount)
TextRecognition.barcodeOutcome(from: [String]) -> BarcodeOutcome  // .none | .found(text, count, url?, firstPayload)

The Vision request setup (VNRecognizeTextRequest/VNDetectBarcodesRequest, recognition level, symbologies) and the toast/alert presentation stay at the call sites — those are AppKit/Vision-coupled and not worth mocking. The three closures now just switch on the outcome.

Scope / safety

  • Behavior-preserving:
    • Same \n join separator; line count is the joined string's component count (matches the old CaptureManager behavior, and equals texts.count in practice since each observation is one line).
    • QR clipboard text is still all payloads joined; the alert still shows the first raw payload (firstPayload, not the normalized URL) and opens the first payload's URL.
    • The if let error guards in both editor closures are untouched.

Tests

TextRecognitionTests (10 cases): OCR empty/whitespace → .noText, single + multi-line join/count; barcode none, URL payload surfaces URL, non-URL → nil URL, mailto: scheme openable, multi-payload joins text while keeping the first for the URL check, and non-URL-first stays nil.

🤖 Generated with Claude Code


Generated by Claude Code

The OCR line-join + empty/line-count logic was duplicated across
CaptureManager.runOCR and EditorView.performOCR, and the QR payload->openable-URL
decision lived inline in performQRScan. Lift the pure post-processing out of the
Vision closures into TextRecognition.ocrOutcome(from:) / barcodeOutcome(from:),
which classify already-extracted strings. The Vision request setup and the
toast/alert presentation stay at the call sites.

Behavior-preserving: same join separator, same line counting (joined components),
clipboard text is still all payloads joined, the alert still shows the first raw
payload and opens the first URL. Adds TextRecognitionTests (10 cases).
@GamalAnwar GamalAnwar merged commit e05b657 into master Jun 18, 2026
1 check passed
@GamalAnwar GamalAnwar deleted the claude/solid-refactor-text-recognition branch June 18, 2026 07:36
GamalAnwar added a commit that referenced this pull request Jun 18, 2026
…12)

Lift the pure OCR/QR post-processing out of the Vision closures in
CaptureManager.runOCR and EditorView.performOCR/performQRScan into
TextRecognition.ocrOutcome(from:) / barcodeOutcome(from:), removing the OCR
line-join/count duplication. Vision setup and toast/alert presentation stay at
the call sites. Behavior-preserving. Adds TextRecognitionTests (10 cases). CI green.
GamalAnwar added a commit that referenced this pull request Jun 18, 2026
…12)

Lift the pure OCR/QR post-processing out of the Vision closures in
CaptureManager.runOCR and EditorView.performOCR/performQRScan into
TextRecognition.ocrOutcome(from:) / barcodeOutcome(from:), removing the OCR
line-join/count duplication. Vision setup and toast/alert presentation stay at
the call sites. Behavior-preserving. Adds TextRecognitionTests (10 cases). CI green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants